//
//  DropViewController.m
//  DebugDemo
//
//  Created by XFB on 2019/1/19.
//  Copyright © 2019年 ZhouCheng. All rights reserved.
//

#import "DropViewController.h"
#import "DropModel.h"

#import "DropMenuView.h"
#import "CoverView.h"

#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"

@interface DropViewController () <DropMenuDataSource>

@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) UIButton *mainButton;

@end

@implementation DropViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupBasicSet];
    [self setupUI];
}

- (void)setupBasicSet
{
    self.navigationItem.title = @"下拉菜单";
    self.view.backgroundColor = UIColorFromRGB(0xEF9800);
}

- (void)setupUI
{
    /// 默认选择0段0行
    DropMenuView *menuView = [[DropMenuView alloc] init];
    menuView.frame = CGRectMake(0, NavBarHeight, ScreenW, 45);
    [self.view addSubview:menuView];
    
    menuView.dataSource = self;
    _titles = @[@"综合", @"销量", @"信用"];
    
    [self setupAllChildViewController];
}

- (void)setupAllChildViewController
{
    OneViewController *vc1 = [[OneViewController alloc] init];
    TwoViewController *vc2 = [[TwoViewController alloc] init];
    ThreeViewController *vc3 = [[ThreeViewController alloc] init];
    [self addChildViewController:vc1];
    [self addChildViewController:vc2];
    [self addChildViewController:vc3];
}

#pragma mark --- <DropMenuDataSource>

- (NSInteger)numberOfColumsInMemu:(DropMenuView *)dropMenuView
{
    return 3;
}

- (UIButton *)dropMenuView:(DropMenuView *)dropMenuView buttonForColumAtIndex:(NSInteger)index
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:_titles[index] forState:UIControlStateNormal];
    [button setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
    [button setTitleColor:UIColorFromRGB(0x1abc9c) forState:UIControlStateSelected];
    return button;
}

- (UIViewController *)dropMenuView:(DropMenuView *)dropMenuView viewControllerForColumAtIndex:(NSInteger)index
{
    return self.childViewControllers[index];
}

- (CGFloat)drppMenuView:(DropMenuView *)dropMenuView heightForColumAtIndex:(NSInteger)index
{
    if (index == 0) {
        return 225;
    }
    
    if (index == 1) {
        return 300;
    }
    
    return 100;
}

@end
